
import LoadingComponent from './Loading.vue';

const Loading = {};

Loading.install = function(Vue) {
    const LoadingContrustor = Vue.extend(LoadingComponent);

    const instance = new LoadingContrustor();

    instance.$mount(document.createElement('div'));

    document.body.appendChild(instance.$el);

    Vue.prototype.$loading = (options) => {
        instance.show();
        if(options) {
            if(options.msg) {
                instance.msg = options.msg;
            }
            if(options.duration) {
                setTimeout(() =>{
                    instance.show = 0;
                },options.duration);
            }
        }
        return instance;
    }
}

export default Loading;